package com.dcliment.jukebox.elements
{
	import flash.display.MovieClip;
	

	public class ContentAnimated extends MovieClip implements IContent
	{
		
		public static const PAUSE:String = "pause";
		public static const PLAY:String = "play";
		public static const RESET:String = "reset";
		public static const RESUME:String = "resume";
		
		
		
		public function ContentAnimated()
		{
			super();
		
			
		}
		
		public function reset():void{

			this.gotoAndStop(1);
			//rewind all movieclips
			timeLineControl(this,ContentAnimated.RESET);
			
		}
		
		
		
		public function start():void{
			//play 	
			this.play();
			timeLineControl(this,ContentAnimated.PLAY);

		}
		
	
		
		public function pause():void{
			
			//pause all playing movieclips
		
			this.stop();
			timeLineControl(this,ContentAnimated.PAUSE);
		
		}
		
		public function resume():void{
			
			trace('=========================================>>>>>RESUME')
		
				if(this.currentFrame <this.totalFrames ){
				
					this.play();
				}
				timeLineControl(this,ContentAnimated.RESUME);

		}
		
		protected function timeLineControl($parentMC:MovieClip,$action:String):void{
			for(var i:uint = 0; i< $parentMC.numChildren; i++){
				
				var theClip:* = $parentMC.getChildAt(i);
				if(theClip is MovieClip){
					
					
					switch($action){
						
						case ContentAnimated.PAUSE:
							theClip.stop();
							
							break;
						
						case ContentAnimated.PLAY:
							
							
							theClip.play();
							break;
						
						case ContentAnimated.RESET:
							theClip.gotoAndStop(1);
							break;
						
						case ContentAnimated.RESUME:
							if(theClip.currentFrame < theClip.totalFrames ){
								theClip.play();
							}
							break;
						
					}
					
					
					
					if(theClip.numChildren>1){
						timeLineControl(theClip,$action);
					}
				}
			}
			
		}
		

	
		
	}
}